#include "Common.h"
#include "Assembler.h"
#include "organ/Organ.h"

Assembler::Assembler()
{

}

Assembler::~Assembler()
{

}

ErrorCode Assembler::AssemblyOrgan(Organ* pOrgan)
{
	if (!pOrgan)
	{
		return eInvalidParam;
	}

	OrganType type = pOrgan->GetType();

	_Organs[type].push_back(pOrgan);
	return eOK;
}

ErrorCode Assembler::Update(uint32 dtTime)
{
	for (uint32 iType = 0; iType < OrganTypeCount; iType++)
	{
		uint32 nOrgan = _Organs[iType].size();
		for (uint32 iOrgan = 0; iOrgan < nOrgan; iOrgan ++)
		{
			Organ* pOrgan = _Organs[ iType][iOrgan];
			if( pOrgan )
			{
				if( !pOrgan->IsReady() )
				{
					pOrgan->Init();
				}
				pOrgan->Update( dtTime );
			}
			
		}
	}
	return eOK;
}

uint32  Assembler::GetOrganCount(OrganType organType)
{
	return _Organs[organType].size();
}

Organ*  Assembler::GetOrgan(OrganType organType, uint32 orgenId )
{
	if( orgenId >= _Organs[organType].size() )
		return NULL;

	return _Organs[organType][orgenId];
}